package com.hejing.project01_谷粒记账软件;

/**
 * ClassName: GuLiAccount
 * Package: com.hejing.project01_谷粒记账软件
 * Description:
 *      阶段1: 谷粒记账软件的基本逻辑实现
 * @Author: HeJing4
 * @Create: 2023-03-25 11:01
 * @Version: 1.0
 */

public class GuLiAccount {
    public static void main(String[] args) {
        boolean isTrue = true;  // 控制循环的结束
        int balance = 100;  // 初始金额
        String info = "";   // 收支明细记录

        while(isTrue){
            System.out.println("-------------------- 谷粒记账软件 ------------------\n");
            System.out.println("                     1 收支明细");
            System.out.println("                     2 登记收入");
            System.out.println("                     3 登记支出");
            System.out.println("                     4 退出");
            System.out.print("                     请选择 1-4: ");

            char selection = Utility.readMenuSelection();  // 获取用户的选择的选项
            switch(selection){
                case '1':
                    // 收支明细
                    System.out.println("------------------- 当前收支明细记录 --------------------");
                    System.out.println("收 支\t\t\t账户余额\t\t\t收支金额\t\t\t说  明\n");
                    System.out.println(info);
                    System.out.println("-----------------------当前收支明细记录-----------------------");
                    break;
                case '2':
                    // 登记收入
                    System.out.print("本次收入金额: ");
                    int money1 = Utility.readNumber();
                    if(money1 > 0) balance += money1;

                    System.out.print("本次收入说明: ");
                    String addDesc = Utility.readString();
                    info += "收 入\t\t\t" + balance + "\t\t\t\t" + money1 + "\t\t\t\t" + addDesc + "\n";

                    System.out.println("-------------------- 登记完成！------------------");

                    break;
                case '3':
                    // 登记收入
                    System.out.print("本次支出金额: ");
                    int money2 = Utility.readNumber();
                    if(money2 > 0 && balance >= money2) balance -= money2;

                    System.out.print("本次支出说明: ");
                    String minusDesc = Utility.readString();
                    info += "支 出\t\t\t" + balance + "\t\t\t\t" + money2 + "\t\t\t\t" + minusDesc + "\n";

                    System.out.println("-------------------- 登记完成！------------------");


                    break;
                case '4':
                    // 登记收入
                    System.out.println("\n请确定是否退出(Y/N): ");
                    char ans = Utility.readConfirmSelection();
                    isTrue = ans == 'Y' || ans == 'y' ? false: true;
                    System.out.println("************** 欢迎下次光临 **************");
                    break;
                default:
                    // 登记收入
                    System.out.println("输入不符合规范!");
                    break;
            }
        }
    }
}